使用二维数组

    const int Cities = 3;
    const int Years = 2;

    int main(int argc, const char * argv[]) {

        using namespace std;

        // const string cities[Cities]
        // const char cities[Cities][25]
        const char * cities[Cities] // 指针数组
        {
            "Shanghai",
            "Beijing",
            "Chengdu"
        };

        int maxtemps[Years][Cities]
        {
            {100, 90, 80},
            {60, 70, 80}
        };

        for (int city = 0; city < Cities; city++) {
            cout << cities[city] << endl;
            for (int year = 0; year < Years; year++) {
                cout << maxtemps[year][city] << endl;
            }
        }

        return 0;
    }

🔚